// packageE/membertool/membertool.js
var app = getApp();
Component({
  properties: {
    datas: {
      type: null
    },
    component_id: {
      type: null
    },
    notShow: {
      type: null
    },
  },
  // 私有数据，可用于模板渲染
  data: {
    emptyImage: 'https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/image.png',

    activeNames: true,
    TemplateArray_1: [],
    TemplateArray_2: []
  },
  lifetimes: {
    // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
    attached() {},
    moved() {},
    detached() {},
  },

  // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
  attached() {},
  // 此处attached的声明会被lifetimes字段中的声明覆盖
  ready() {
  },

  methods: {
    errorFunction(event) {
      let index = event.currentTarget.dataset.index;
      let img = 'datas.show_list[' + index + '].image';
      this.setData({
        [img]: 'https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/image.png'
      });
    }, 
    //获取模板id
    getTemplate_1(name) {
      let urlStr = app.getNetAddresss("member.member.getMiniTemplateCorrespond");
      let that = this;
      app._getNetWork({
        url: urlStr,
        data: {
          small_type: 4
        },
        success: function(resdata) {
          var res = resdata.data;
          if (res.result == 1) {
            let array = [];
            for (let i = 0; i < res.data.length; i++) {
              array.push(res.data[i].template_id);
            }
            that.setData({
              TemplateArray_1: array
            });
            wx.requestSubscribeMessage({
              tmplIds: that.data.TemplateArray_1,
              success(res) {
                if(name == 'supplier'){
                  wx.navigateTo({
                    url: '/packageA/member/supplier/supplier',
                  })
                }else{
                  wx.navigateTo({
                    url: '/packageA/member/SupplierCenter/SupplierCenter?uid=' + that.data.supplier_id
                  });
                }
              },
              fail() {
                if(name == 'supplier'){
                  wx.navigateTo({
                    url: '/packageA/member/supplier/supplier',
                  })
                }else{
                  wx.navigateTo({
                    url: '/packageA/member/SupplierCenter/SupplierCenter?uid=' + that.data.supplier_id
                  });
                }
              }
            });
          } else {
            wx.showToast({
              title: res.msg,
              icon: 'none',
              duration: 1500
            });
          }
        },
        fail: function(res) {
          console.log(res);
        }
      });
    },
    //获取模板id
    getTemplate_2() {
      let urlStr = app.getNetAddresss("member.member.getMiniTemplateCorrespond");
      let that = this;
      app._getNetWork({
        url: urlStr,
        data: {
          small_type: 5
        },
        success: function(resdata) {
          var res = resdata.data;
          if (res.result == 1) {
            let array = [];
            for (let i = 0; i < res.data.length; i++) {
              array.push(res.data[i].template_id);
            }
            that.setData({
              TemplateArray_2: array
            });
            wx.requestSubscribeMessage({
              tmplIds: that.data.TemplateArray_2,
              success(res) {
                wx.navigateTo({
                  url: '/packageC/o2o/storeManage/storeManage'
                });
              },
              fail() {
                wx.navigateTo({
                  url: '/packageC/o2o/storeManage/storeManage'
                });
              }
            });
          } else {
            wx.showToast({
              title: res.msg,
              icon: 'none',
              duration: 1500
            });
          }
        },
        fail: function(res) {
          console.log(res);
        }
      });
    },
    //根据后台返回名字做跳转
    pluginGoto(e) {
      let item = e.currentTarget.dataset.item;
      let url = item.url;
      // //跳转到门店管理
      if (item.url == 'storeManage') {
        this.gostoreManage();
        return;
      }
      //跳转到推广中心
      if (item.url == 'extension') {
        this.goextension();
        return;
      }

      if (item.name == "courier") {
        wx.setStorage({
          key: 'couriername',
          data: item.title
        });
        wx.navigateTo({
          url: '/packageA/member/' + url + '/' + url
        });
      } else if (item.name == "supplier" || item.name == "SupplierCenter") {
        let that = this;
        that.getTemplate_1(item.url);
        // wx.navigateTo({
        //   url: '/packageA/member/' + url + '/' + url + '?uid=' + this.data.supplier_id
        // });
      } else if (item.url == "HotelManage") {
        wx.navigateTo({
          url: '/packageA/hotel/HotelManage/HotelManage?title=' +
					encodeURIComponent("酒店管理")
        });
      } else if (item.url == 'aftersaleslist') {
        this.goaftersaleslist();
      } else if (item.url == 'helperLiveList') {
        this.getTemplate();
      }else if (item.url == 'subsidiary') {
        wx.navigateTo({
          url: '/packageA/member/myOrder_v2/myOrder_v2?status=0&orderType=subsidiary'
        });
      }  else if (item.url == 'cloudIndex') {
        wx.navigateTo({
          url: '/packageE/others/cloudwarehouse/cloud_index/cloud_index'
        });
      } else {
        wx.navigateTo({
          url: item.mini_url
			
        });
      } 

      // if (item.name == "courier") {
      // 	wx.setStorage({
      // 		key: 'couriername',
      // 		data: item.title
      // 	})
      // 	wx.navigateTo({
      // 		url: '/packageA/member/' + url + '/' + url
      // 	})
      // } else if (item.name == 'universal_card') {
      // 	// 跳转到一卡通页面
      // 	wx.navigateTo({
      // 		url: '/packageB/member/CardIndex/CardIndex'
      // 	})
      // } else if (item.name == "supplier" && item.url == "SupplierCenter") {
      // 	let that = this;
      // 	that.getTemplate_1();
      //
      // } else if (item.name == "supplier") {
      // 	wx.navigateTo({
      // 		url: '/packageA/member/' + url + '/' + url + '?uid=' + this.data.supplier_id
      // 	})
      // } else if (item.url == 'creditInfo') {
      // 	wx.navigateTo({
      // 		url: '/packageB/member/' + url + '/' + url
      // 	})
      // } else if (item.url == 'Integral_love') {
      // 	wx.navigateTo({
      // 		url: '/packageB/member/' + url + '/' + url
      // 	})
      // } else if (item.url == 'hotelApply') {
      // 	wx.navigateTo({
      // 		url: '/packageA/member/storeApply/storeApply?name=hotelApply'
      // 	})
      // } else if (item.url == "HotelManage") {
      // 	wx.navigateTo({
      // 		url: '/packageA/hotel/HotelManage/HotelManage?title=' +
      // 			encodeURIComponent("酒店管理")
      // 	})
      // } else if (item.url == "CardCenter") {
      // 	wx.navigateTo({
      // 		url: '/packageB/member/business_card/CardCenter/CardCenter'
      // 	})
      // } else if (item.url == "materialCenter") {
      // 	wx.navigateTo({
      // 		url: '/packageA/others/materialCenter/materialCenter'
      // 	})
      // } else if (item.url == 'DistributionOrders') {
      // 	wx.navigateTo({
      // 		url: '/packageA/member/DistributionOrders/DistributionOrders'
      // 	})
      // } else if (item.url == 'MyGroups') {
      // 	wx.navigateTo({
      // 		url: '/packageB/member/group/MyGroups/MyGroups'
      // 	})
      // } else if (item.url == 'SelfCarryApply') {
      // 	wx.navigateTo({
      // 		url: '/packageC/selfCarry/selfCarryApply/selfCarryApply'
      // 	})
      // } else if (item.url == 'auctioneer') {
      // 	wx.navigateTo({
      // 		url: '/packageD/auction/auctioneer-manage/auctioneer/auctioneer'
      // 	})
      // } else if (item.url == 'auctionIndex') {
      // 	wx.navigateTo({
      // 		url: '/packageD/auction/auction/auction_index/auction_index'
      // 	})
      // } else if (item.url == 'auctionApply') {
      // 	wx.navigateTo({
      // 		url: '/packageD/auction/auction-apply/auction-apply/auction-apply'
      // 	})
      // } else if (item.url == 'SelfCarryApply') {
      // 	wx.navigateTo({
      // 		url: '/packageC/selfCarry/selfCarryApply/selfCarryApply'
      // 	})
      // } else if (item.url == 'aftersaleslist') {
      // 	this.goaftersaleslist()
      // } else if (item.url == 'collection') {
      // 	this.gocollection()
      // } else if (item.url == 'footprint') {
      // 	this.gofootprint()
      // } else if (item.url == 'myEvaluation') {
      // 	this.gomyEvaluation()
      // } else if (item.url == 'myRelationship') {
      // 	this.gomyRelationship();
      // } else if (item.url == 'address') {
      // 	this.goaddress()
      // } else if (item.url == 'coupon') {
      // 	this.gocoupon();
      // } else if (item.url == 'info') {
      // 	this.goinfo()
      // } else if (item.url == 'sign') {
      // 	this.gosign()
      // } else if (item.url == 'anchorApply') {
      // 	wx.navigateTo({
      // 		url: '/packageD/directSeeding/anchorApply/anchorApply'
      // 	})
      // } else if (item.url == 'liveList') {
      // 	wx.navigateTo({
      // 		url: '/packageD/directSeeding/liveList/liveList'
      // 	})
      // } else if (item.url == 'MyVoices') {
      // 	wx.navigateTo({
      // 		url: '/packageC/voice_shop/my_voices/my_voices'
      // 	})
      // } else if (item.url == 'subsidiary') {
      // 	wx.navigateTo({
      // 		url: '/packageA/member/myOrder_v2/myOrder_v2?status=0&orderType=subsidiary'
      // 	})
      // } else if (item.url == 'Appointment') {
      //  wx.navigateTo({
      //    url: '/packageE/appointment/appointment_index'
      //  })
      // }
      // else {
      // 	wx.navigateTo({
      // 		url: '/packageA/member/' + url + '/' + url
      // 	})
      // }
    },
    goaftersaleslist: function() {
      wx.navigateTo({
        url: '/packageD/member/myOrder/Aftersaleslist/Aftersaleslist'
      });

    },
    //跳到收藏页面
    gocollection(e) {
      wx.navigateTo({
        url: '/packageD/member/collection/collection'
      });
    },
    //跳转到足迹
    gofootprint(e) {
      wx.navigateTo({
        url: '/packageD/member/footprint/footprint'
      });

    },
    //跳转到评论页
    gomyEvaluation(e) {
      wx.navigateTo({
        url: '/packageD/member/myEvaluation/myEvaluation'
      });
    },
    //跳转到客户
    gomyRelationship(e) {
      //myRelationship
      wx.navigateTo({
        url: '/packageD/member/myRelationship/myRelationship'
      });
    },
    //跳转到地址
    goaddress(e) {
      wx.navigateTo({
        url: '/packageD/member/addressList/addressList'
      });
    },
    //跳转到优惠
    gocoupon(e) {
      wx.navigateTo({
        url: '/packageA/member/coupon_v2/coupon_v2'
      });
    },
    //跳转到设置
    goinfo(e) {
      wx.navigateTo({
        url: '/packageA/member/info/info'
      });
    },
    //跳到签到页面
    gosign() {
      //sign
      wx.navigateTo({
        url: '/packageA/member/sign/sign'
      });
    },
    //跳转到收银台
    gocashier() {
      wx.navigateTo({
        url: '/packageC/cashier/cashier/cashier'
      });
    },
    //跳转到微店
    gomicroShop_home() {
      wx.navigateTo({
        url: '/packageC/microshop/microShop_home/microShop_home'
      });
      //microShop_home
    },
    //跳转到我要开店
    gomicroShop_apply() {
      //microShop_apply
      wx.navigateTo({
        url: '/packageC/microshop/microShop_apply/microShop_apply'
      });
    },
    //跳转到华侨币
    gooverseas_index() {
      //overseas_index
      wx.navigateTo({
        url: '/packageB/member/overseas_index/overseas_index'
      });
    },
    //跳转到门店管理
    gostoreManage() {
      this.getTemplate_2();
      //storeManage
    },
    //跳装到帮助页面
    gohelpcenter() {
      wx.navigateTo({
        url: '/packageB/member/helpcenter/helpcenter'
      });

    },
    //跳装到冻结币
    goFrozenCoin() {
      //FrozenCoin
      wx.navigateTo({
        url: '/packageB/member/FrozenCoin/FrozenCoin'
      });
    },
    //跳到爱心兑换值
    golove_index: function() {
      //love_index
      wx.navigateTo({
        url: '/packageB/member/love/Love_index/Love_index'
      });
    },
    goextension: function() {
      //extension
      wx.reLaunch({
        url: '/packageG/pages/member/extension/extension'
      });
    },
    onChange(event) {
      this.setData({
        activeNames: !this.data.activeNames
      });
    },
    gotoUrl(e) {
      let url = e.currentTarget.dataset.item.h5_link;
      try {
        wx.navigateTo({
          url: url
        });
      } catch (e) {
        wx.showToast({
          title: '链接设置错误',
          icon: 'none',
          duration: 2000
        });
      }
    }
  }
});
